package com.lizhi.yun.core.handler;/**
 * @program: sfrobot-html
 * @name StandAppointHandler
 * @description:
 * @author: lizhi
 * @create: 2020-05-26 17:42
 */

import com.lizhi.common.yun.entity.ListResponseResult;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.stand.dao.StandAppointDao;
import com.lizhi.yun.db.stand.dao.StandPtInfoDao;
import com.lizhi.yun.db.stand.pojo.StandAppointPOJO;
import com.lizhi.yun.db.stand.pojo.StandPtInfoPOJO;
import com.lizhi.mybatis.interceptor.PageBounds;
import com.lizhi.utils.StringUtils;
import com.lizhi.yun.deploy.NewBaseHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 *@program: sfrobot-html
 *@name StandAppointHandler
 *@description: 康复预约
 *@author: lizhi
 *@create: 2020-05-26 17:42
 */
@Slf4j
@Service
public class ServiceAppointHandler extends NewBaseHandler {

    @Resource
    private StandPtInfoDao standPtInfoDao;

    @Resource
    private StandAppointDao standAppointDao;

    /*
     *功能描述
     * @author lizhi
     * @date 2020/6/4
     * @param json:
     * @return com.lizhi.common.entity.ListResult<com.lizhi.db.pojo.StandAppointPOJO>
     */
    public ListResponseResult doMain(String json){
        Map<String, Object> map = SamJsonUtil.toMap(json);
        /*先查询出登录人信息*/
        PageBounds pageBounds = getPageBounds(map);
        List<StandAppointPOJO> list = standAppointDao.selectByMap(map, pageBounds);
        for (int i = 0; i < list.size(); i++){
            /*查询患者信息*/
            StandPtInfoPOJO standPtInfoPOJO = standPtInfoDao.selectById(list.get(i).getAppointPtId(), list.get(i).getHospitalId(), list.get(i).getHospitalSystemId());
            if (!StringUtils.isEmpty(standPtInfoPOJO)){
                list.get(i).setPtDoctor(standPtInfoPOJO.getPtDoctor());
            }
        }
        log.info("查询到的预约信息是StandAppointPOJOs:{}", list);
        return getListResult(pageBounds.getCountRows(), list, map);
    }

}
